import {
  Row,
  Col,
  Form,
  Input,
  Select,
  Modal
} from 'antd';
import SelectDeptTree from '@/components/SelectDeptTree';
const FormItem = Form.Item;
const { Option } = Select;

//新增表单
let getDeptTreeBySelectTree;
const CreateForm = Form.create()(props => {
  const { 
  	modalVisible, 
  	form, 
  	handleAdd, 
  	handleModalVisible,
  	dispatch,
	requestModelName,
  	selectDeptTree
  } = props;
  
  const selectedDeptTreeValue = (deptRecord) => {
		getDeptTreeBySelectTree = deptRecord;
	}
  
  const parentDeptTreeMethod = {
		dispatch,
		selectDeptTree,
		selectedDeptTreeValue,
		requestModelName
	}
  
  const okHandle = () => {
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      form.resetFields();
      if(getDeptTreeBySelectTree) {
				fieldsValue.levelcode = getDeptTreeBySelectTree.triggerNode.props.dataRef.levelcode;
				fieldsValue.parentid = getDeptTreeBySelectTree.triggerNode.props.dataRef.key;
				fieldsValue.parent_name = getDeptTreeBySelectTree.triggerNode.props.dataRef.title;
			}else {
				fieldsValue.levelcode = "000000000000";
				fieldsValue.parentid = "000000000000";
			}
      handleAdd(fieldsValue);
    });
  };
  return (
    <Modal
width={800}
destroyOnClose
title="新增"
visible={modalVisible}
onOk={okHandle}
onCancel={() => handleModalVisible()}
>
<Form  layout="vertical">

    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

        <Col  md={12} sm={24}>
	        <FormItem  label="名称">
	            {form.getFieldDecorator('dept_name', {
	            rules: [{ required: true, message: '请输入部门名称！', min: 1 }],
	            })(<Input placeholder="请输入" />)}
	        </FormItem>
        </Col>
				
		<Col  md={12} sm={24}>
	        <FormItem  label="上级部门">
	        	{form.getFieldDecorator('dept')(
               	<SelectDeptTree {...parentDeptTreeMethod} />
	          )}
	        </FormItem>
        </Col>


        {/*<Col  md={12} sm={24}>
		        <FormItem  label="部门code">
		            {form.getFieldDecorator('dept_code', {
		            rules: [{ required: true, message: '请输入部门code！', min: 1 }],
		            })(<Input placeholder="请输入" />)}
		        </FormItem>
        </Col>*/}

    </Row>
    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

       	<Col md={12} sm={24}>
		        <FormItem label="状态">
		            {form.getFieldDecorator('enable',{
		            	initialValue: "1",
		            })(
		                <Select placeholder="请选择" style={{ width: '100%' }}>
		                		<Option value="1">可用</Option>
		                    <Option value="0">禁用</Option>
		                </Select>
		            )}
		        </FormItem>
        </Col>
				
        <Col  md={12} sm={24}>
		        <FormItem  label="描述">
		            {form.getFieldDecorator('dept_description', {
		            rules: [{ required: false }],
		            })(<Input placeholder="请输入" />)}
		        </FormItem>
        </Col>


    </Row>

    {/*<Row gutter={{ md: 8, lg: 24, xl: 48 }}>

        <Col  md={12} sm={24}>
		        <FormItem  label="层叠样式">
		            {form.getFieldDecorator('cls', {
		            rules: [{ required: false, message: '请输入层叠样式！', min: 1 }],
		            })(<Input placeholder="请输入" />)}
		        </FormItem>
        </Col>
        <Col  md={12} sm={24}>
		        <FormItem  label="上级部门">
		        	{form.getFieldDecorator('dept')(
	               	<SelectDeptTree {...parentDeptTreeMethod} />
		          )}
		        </FormItem>
        </Col>

    </Row>
    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

       <Col md={12} sm={24}>
        <FormItem label="是否叶子">
            {form.getFieldDecorator('leaf')(
                 <Select placeholder="请选择" style={{ width: '100%' }}>
                        <Option value="0">是</Option>
                         <Option value="1">否</Option>
                 </Select>
            )}
        </FormItem>
        </Col>

        <Col  md={12} sm={24}>
        <FormItem  label="图标">
            {form.getFieldDecorator('icon', {
            rules: [{ required: false, message: '请输入至少五个字符的父部门Id！', min: 5 }],
            })(<Input placeholder="请输入" />)}
        </FormItem>
        </Col>

    </Row>
		<Row gutter={{ md: 8, lg: 24, xl: 48 }}>


        <Col  md={12} sm={24}>
	        <FormItem  label="父部门Id">
	            {form.getFieldDecorator('parent_id', {
	            rules: [{ required: false, message: '请输入至少五个字符的父部门Id！', min: 5 }],
	            })(<Input placeholder="请输入" />)}
	        </FormItem>
        </Col>


        <Col  md={12} sm={24}>
	        <FormItem  label="层次码">
	            {form.getFieldDecorator('levelcode', {
	            rules: [{ required: false, message: '请输入至少五个字符的父部门Id！', min: 5 }],
	            })(<Input placeholder="请输入" />)}
	        </FormItem>
        </Col>

    </Row>*/}
</Form>
</Modal>
  );
});

export default CreateForm;


